package com.xuexuehai.carrecommand.exception.handler;

import com.xuexuehai.carrecommand.dto.HttpResp;
import com.xuexuehai.carrecommand.exception.enums.SysStatusEnums;
import com.xuexuehai.carrecommand.exception.user.*;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author xuexuehai
 * @mailBox xuehai.xue@QQ.com
 * @date 2021/8/19 9:34 上午
 *
 * 拦截请求Exception
 */
@RestControllerAdvice
public class UserExceptionHandler {
    @ExceptionHandler
    public HttpResp handleAccountNotNull(AccountNotNullException e){
        return new HttpResp(SysStatusEnums.ACCOUNT_NOT_NULL.getCode(),
                e.getMessage(),null,null);
    }

    @ExceptionHandler
    public HttpResp handleInvalidUser(InvalidUserException e){
        return new HttpResp(SysStatusEnums.INVALID_USER.getCode(),
                e.getMessage(),null,null);
    }

    @ExceptionHandler
    public HttpResp handleUsernameNotFound(UsernameNotFoundException e){
        return new HttpResp(SysStatusEnums.USERNAME_NOT_FOUND.getCode(),
                e.getMessage(),null,null);
    }

    @ExceptionHandler
    public HttpResp handleUserPrivsIncorrect(UserPrivsIncorrectException e){
        return new HttpResp(SysStatusEnums.INCORRECT_USER_PRIVS.getCode(),
                e.getMessage(),null,null);
    }

    @ExceptionHandler
    public HttpResp handleNotLogin(NotLoginException e){
        return new HttpResp(SysStatusEnums.NOT_LOGIN.getCode(),
                e.getMessage(),null,null);
    }

    @ExceptionHandler
    public HttpResp handleUsernameUsed(UsernameUsedException e){
        return new HttpResp(SysStatusEnums.USERNAME_USED.getCode(),
                e.getMessage(),null,null);
    }
}
